import mime from 'mime'
const path = global.path

export class SaveFile {
  constructor() {
    this.uuid = 'acd' + Date.now()
    this.data = []
  }
  append(blob) {
    this.data.push(Buffer.from(blob))
  }
  getValue() {
    return  Buffer.concat(this.data);
  }
}

const fs = global.fs
export function saveFile(content, basePath, options) {
  try {
    fs.writeFileSync(path.join(basePath, options.filename + '.' + mime.getExtension(options.type)), content, 'utf-8')
  }
  catch(e) {
    console.log('Failed to save the file !')
    console.error(e)
  }
}
